package com.example.shippxy.utils;

import com.alibaba.fastjson.JSONObject;
import com.example.shippxy.constant.Constant;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class JSONObjectUtils {
    public static void main(String[] args) throws InterruptedException {
        Map<String,Object> map = json2Map();
        mapTest(map);

    }

    private static Map json2Map(){
        String ships = "{\"413523180\":\"五指山\",\"413523230\":\"尖峰岭\",\"413523240\":\"鹦哥岭\",\"413523220\":\"铜鼓岭\",\"413523210\":\"白石岭\",\"413523190\":\"黎母岭\",\"413522050\":\"海峡一号\",\"413521120\":\"宝岛12号\",\"413522220\":\"宝岛16号\",\"412522670\":\"信海12号\",\"413520260\":\"信海16号\",\"413522110\":\"信海19号\",\"413523990\":\"凤凰岭\",\"413524010\":\"六连岭\",\"413523980\":\"海棠湾\",\"413522480\":\"海口六号\",\"413523430\":\"海口九号\",\"413525630\":\"海口16号\",\"413234410\":\"海装8号\",\"413231340\":\"紫荆二十三\",\"413232860\":\"海峡二号\",\"413232890\":\"金紫荆\",\"413233380\":\"银紫荆\",\"413232470\":\"紫荆二十二\",\"413234440\":\"紫荆九号\",\"413232490\":\"紫荆十二\",\"413233350\":\"紫荆十六\",\"413232480\":\"紫荆十五\",\"413233370\":\"紫荆十一\",\"413233360\":\"双泰11\",\"413233560\":\"双泰12\",\"413231030\":\"双泰16\",\"413233570\":\"双泰18\",\"413233580\":\"双泰19\",\"413233590\":\"双泰26\",\"413233620\":\"双泰27\",\"413233240\":\"双泰28\",\"413233650\":\"双泰29\",\"413233630\":\"双泰36\",\"413233640\":\"双泰37\",\"413234380\":\"双泰宝昌\",\"413234430\":\"海装2号\",\"413234420\":\"海装6号\",\"413234390\":\"海装18号\",\"413234720\":\"南方6号\",\"413234660\":\"腾胜宝昌\",\"413234640\":\"扬帆海安\"}";
        JSONObject json = JSONObject.parseObject(ships);
        Map<String, Object> map = json.getInnerMap();
        return map;
    }

    private static void mapTest(Map map) throws InterruptedException {
        Iterator<Map.Entry<String, Object>> iterator = map.entrySet().iterator();
        int index = 0;
        List<String> mmsiList = new ArrayList<>();
        while (index < 5) {
            if (iterator.hasNext())
                index++;
            else
                break;
            Map.Entry<String, Object> next = iterator.next();
            mmsiList.add(next.getKey());
            //每五个mmsi休眠3秒
            if (index >= 5 || !iterator.hasNext()) {
                System.out.println(mmsiList);
                mmsiList.clear();
                index = 0;
                Thread.sleep(300);
            }
        }
    }
}
